﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace QualityJudgingApp
{
    public partial class Form1 : Form
    {
        string rawLogFile = "";
        string tagLogFile = "";
        List<RawDataEntry> rawDataList = new List<RawDataEntry>();
        AnalysisLogic analysisLogic = null;

        int trainingSizeUpper = 95;
        int trainingSizeInterval = 10;
        int eachSimuluationUpperLimit = 10;
        int workerSizeUpper = 5;
        int workerSizeStart = 2;
        int eachWorkerPickingSimuLimit = 5;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ReadDataFiles();
        }

        private void SimuAnalysis()
        {
            if (null == analysisLogic)
                analysisLogic = new AnalysisLogic(rawDataList);

            int total = trainingSizeUpper / trainingSizeInterval * eachSimuluationUpperLimit * (workerSizeUpper-1) * eachWorkerPickingSimuLimit;
            int current = 0;
            List<int> userIDs = analysisLogic.getAllUserIDs();
            List<int> internalIDs = new List<int>();
            for (int i = 0; i < 5; i++)
                internalIDs.Add(i);
            //for each number of workers
            string output = "";
            double[, ,] PosRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] NegRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] precisionRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] recallRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] fvalueRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] fvalueRatio2 = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] accuracys = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            //double[, ,] accuracy = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] optimalX = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            for (int WN = 2; WN <= workerSizeUpper; WN++)
            {
                //fixed # of workers, for each picking
                for (int k = 0; k < eachWorkerPickingSimuLimit; k++)
                {
                    //for each training size
                    for (int N = 1; N <= trainingSizeUpper / trainingSizeInterval; N++)
                    {
                        //for each simu for each training*worker picking
                        int run = eachSimuluationUpperLimit;
                        while (run > 0)
                        {
                            current++;
                            System.Diagnostics.Debug.WriteLine("Status: " + current + " out of "+total+" \n\n");
                            List<int> chosenIDs = new List<int>();
                            Random myR = new Random();
                            for (int i = 0; i < N * trainingSizeInterval; i++)
                            {
                                int nextId = myR.Next(0, userIDs.Count);
                                if (!chosenIDs.Contains(userIDs[nextId]))
                                    chosenIDs.Add(userIDs[nextId]);
                                else
                                    i--;
                            }

                            List<int> chosenInternalIDs = new List<int>();
                            for (int i = 0; i < WN; i++)
                            {
                                int nextId = myR.Next(0, internalIDs.Count);
                                if (!chosenInternalIDs.Contains(internalIDs[nextId]))
                                    chosenInternalIDs.Add(internalIDs[nextId]);
                                else
                                    i--;
                            }
                            analysisLogic.GetParameters(chosenIDs, chosenInternalIDs);
                            analysisLogic.NewAnalyzeSelectProfiles(chosenIDs, chosenInternalIDs);
                            PosRatio[WN - 2, N - 1, k] += analysisLogic.CurrentPosRatio;
                            NegRatio[WN - 2, N - 1, k] += analysisLogic.CurrentNegRatio;
                            precisionRatio[WN - 2, N - 1, k] += analysisLogic.precision;
                            recallRatio[WN - 2, N - 1, k] += analysisLogic.recall;
                            //fvalueRatio[WN - 2, N - 1, k] += analysisLogic.fvalue;
                            //fvalueRatio2[WN - 2, N - 1, k] += analysisLogic.fvalue2;
                            //accuracys[WN - 2, N - 1, k] += analysisLogic.accuracy;
                            fvalueRatio[WN - 2, N - 1, k] = fvalueRatio[WN - 2, N - 1, k] > analysisLogic.fvalue ? fvalueRatio[WN - 2, N - 1, k] : analysisLogic.fvalue;
                            fvalueRatio2[WN - 2, N - 1, k] = fvalueRatio2[WN - 2, N - 1, k] > analysisLogic.fvalue2 ? fvalueRatio2[WN - 2, N - 1, k] : analysisLogic.fvalue2;
                            accuracys[WN - 2, N - 1, k] = accuracys[WN - 2, N - 1, k] > analysisLogic.accuracy ? accuracys[WN - 2, N - 1, k] : analysisLogic.accuracy;
                            //accuracy[WN - 2, N - 1, k] += analysisLogic.accuracy;
                            optimalX[WN - 2, N - 1, k] += analysisLogic.optimalX;
                            //output += WN + "\t" + (k + 1) + "\t" + chosenIDs.Count + "\t" + analysisLogic.NewAnalyzeSelectProfiles(chosenIDs, chosenInternalIDs) + "\n";
                            //for (int mm = 0; mm < 2; mm++)
                            //{
                            //    analysisLogic.GetParameters(chosenIDs, chosenInternalIDs, mm);
                            //    for(int nn=3; nn>=0;nn--)
                            //        richTextBox1.Text += (mm+1)+"\t"+(nn)+"\t" + WN + "\t" + (k + 1) + "\t" + chosenIDs.Count + "\t" + analysisLogic.NewAnalyzeSelectProfiles(chosenIDs, chosenInternalIDs, nn) + "\n";
                            //}
                            run--;
                        }
                    }
                }
            }

            for(int i=0; i<workerSizeUpper-1;i++)
                for (int j = 0; j < trainingSizeUpper / trainingSizeInterval; j++)
                    for (int k = 0; k < eachWorkerPickingSimuLimit; k++)
                    {
                        output += "0\t" + (i + 2) 
                                    + "\t" + (j + 1) * trainingSizeInterval + "\t"
                                    + (precisionRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    + (recallRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    //+ (fvalueRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    //+ (fvalueRatio2[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    //+ (accuracys[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    + (fvalueRatio[i, j, k]) + "\t"
                                    + (fvalueRatio2[i, j, k]) + "\t"
                                    + (accuracys[i, j, k]) + "\t"
                                    //+ (optimalX[i, j, k] / eachSimuluationUpperLimit) 
                                    + "\n";
                    }

            richTextBox1.Text += output;
        }

        private void SimuAnalysis2()
        {
            AnalysisLogic2 analysisLogic = new AnalysisLogic2(rawDataList);

            int total = trainingSizeUpper / trainingSizeInterval * eachSimuluationUpperLimit * (workerSizeUpper - 1) * eachWorkerPickingSimuLimit;
            int current = 0;
            List<int> userIDs = analysisLogic.getAllUserIDs();
            List<int> internalIDs = new List<int>();
            for (int i = 0; i < 5; i++)
                internalIDs.Add(i);
            //for each number of workers
            string output = "";
            double[, ,] PosRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] NegRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] precisionRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] recallRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] fvalueRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] fvalueRatio2 = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] accuracys = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] optimalY = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];

            for (int WN = 2; WN <= workerSizeUpper; WN++)
            {
                //fixed # of workers, for each picking
                for (int k = 0; k < eachWorkerPickingSimuLimit; k++)
                {
                    //for each training size
                    for (int N = 1; N <= trainingSizeUpper / trainingSizeInterval; N++)
                    {
                        //for each simu for each training*worker picking
                        int run = eachSimuluationUpperLimit;
                        while (run > 0)
                        {
                            if (WN == 3)
                            {
                                int x = 1;
                            }

                            current++;
                            System.Diagnostics.Debug.WriteLine("Status: " + current + " out of " + total + " \n\n");
                            List<int> chosenIDs = new List<int>();
                            Random myR = new Random();
                            for (int i = 0; i < N * trainingSizeInterval; i++)
                            {
                                int nextId = myR.Next(0, userIDs.Count);
                                if (!chosenIDs.Contains(userIDs[nextId]))
                                    chosenIDs.Add(userIDs[nextId]);
                                else
                                    i--;
                            }

                            List<int> chosenInternalIDs = new List<int>();
                            for (int i = 0; i < WN; i++)
                            {
                                int nextId = myR.Next(0, internalIDs.Count);
                                if (!chosenInternalIDs.Contains(internalIDs[nextId]))
                                    chosenInternalIDs.Add(internalIDs[nextId]);
                                else
                                    i--;
                            }
                            analysisLogic.Evaluate(chosenIDs, chosenInternalIDs);
                            PosRatio[WN - 2, N - 1, k] += analysisLogic.CurrentPosRatio;
                            NegRatio[WN - 2, N - 1, k] += analysisLogic.CurrentNegRatio;
                            precisionRatio[WN - 2, N - 1, k] += analysisLogic.precision;
                            recallRatio[WN - 2, N - 1, k] += analysisLogic.recall;
                            //fvalueRatio[WN - 2, N - 1, k] += analysisLogic.fvalue;
                            //fvalueRatio2[WN - 2, N - 1, k] += analysisLogic.fvalue2;
                            //accuracys[WN - 2, N - 1, k] += analysisLogic.accuracy;
                            fvalueRatio[WN - 2, N - 1, k] = fvalueRatio[WN - 2, N - 1, k] > analysisLogic.fvalue ? fvalueRatio[WN - 2, N - 1, k] : analysisLogic.fvalue;
                            fvalueRatio2[WN - 2, N - 1, k] = fvalueRatio2[WN - 2, N - 1, k] > analysisLogic.fvalue2 ? fvalueRatio2[WN - 2, N - 1, k] : analysisLogic.fvalue2;
                            accuracys[WN - 2, N - 1, k] = accuracys[WN - 2, N - 1, k] > analysisLogic.accuracy ? accuracys[WN - 2, N - 1, k] : analysisLogic.accuracy;

                            optimalY[WN - 2, N - 1, k] += analysisLogic.optimalY;
                            //output += WN + "\t" + (k + 1) + "\t" + chosenIDs.Count + "\t" + analysisLogic.NewAnalyzeSelectProfiles(chosenIDs, chosenInternalIDs) + "\n";
                            //for (int mm = 0; mm < 2; mm++)
                            //{
                            //    analysisLogic.GetParameters(chosenIDs, chosenInternalIDs, mm);
                            //    for(int nn=3; nn>=0;nn--)
                            //        richTextBox1.Text += (mm+1)+"\t"+(nn)+"\t" + WN + "\t" + (k + 1) + "\t" + chosenIDs.Count + "\t" + analysisLogic.NewAnalyzeSelectProfiles(chosenIDs, chosenInternalIDs, nn) + "\n";
                            //}
                            run--;
                        }
                    }
                }
            }

            for (int i = 0; i < workerSizeUpper - 1; i++)
                for (int j = 0; j < trainingSizeUpper / trainingSizeInterval; j++)
                    for (int k = 0; k < eachWorkerPickingSimuLimit; k++)
                    {
                        output += "1\t" + (i + 2)
                                    + "\t" + (j + 1) * trainingSizeInterval + "\t"
                                    + (precisionRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    + (recallRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                            //+ (fvalueRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                            //+ (fvalueRatio2[i, j, k] / eachSimuluationUpperLimit) + "\t"
                            //+ (accuracys[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    + (fvalueRatio[i, j, k]) + "\t"
                                    + (fvalueRatio2[i, j, k]) + "\t"
                                    + (accuracys[i, j, k]) + "\t"
                            //+ (optimalX[i, j, k] / eachSimuluationUpperLimit) 
                                    + "\n";
                    }

            richTextBox1.Text += output;
        }

        private void ReadDataFiles()
        {
            //if (File.Exists(rawLogFile) && File.Exists(tagLogFile))
            if (File.Exists(rawLogFile))
            {
                TextReader tr = new StreamReader(rawLogFile);
                // TextReader trTag = new StreamReader(tagLogFile);
                // read a line of text
                string tempLine = null;
                //string tempLineTag = null;
                //tempLine = tr.ReadLine();
                //tempLine = tr.ReadLine();
                //skip the first two lines as they are log header
                tempLine = tr.ReadLine();
                // tempLineTag = trTag.ReadLine();

                int controlID = 1;
                int internalCount = 0;

                while (tempLine != null)//only first 5 will be needed
                {
                    //RawDataEntry tempRawLog = new RawDataEntry(tempLine);
                    RawDataEntry tempRawLog = new RawDataEntry(tempLine, controlID);
                    internalCount++;
                    if (internalCount == 5)
                    {
                        internalCount = 0;
                        controlID++;
                    }

                    // string[] tags = tempLineTag.Split('\t');
                    // int tagNow = int.Parse(tags[1]);
                    // tempRawLog.Quality = tagNow;

                    rawDataList.Add(tempRawLog);
                    tempLine = tr.ReadLine();
                    // tempLineTag = trTag.ReadLine();
                }
                // close the stream
                tr.Close();
                // trTag.Close();
            }
            else
            {
                MessageBox.Show("Data Files Missing! \nMake sure you download that file and put it in the same folder as exe file please!");
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //read raw data file
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            dialog.InitialDirectory = Directory.GetCurrentDirectory();
            dialog.Title = "Select RAW log data file";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                rawLogFile = dialog.FileName;
                this.richTextBox2.Text += "Status: Raw Data Successfully Loaded";
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //read tagging data file
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            dialog.InitialDirectory = Directory.GetCurrentDirectory();
            dialog.Title = "Select tagging log data file";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                tagLogFile = dialog.FileName;
                this.richTextBox2.Text += "Status: Tagging Data Successfully Loaded\n";
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            SimuAnalysis();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            double[] w = {1	,
                        1	,
                        1	,
                        1	,
                        1	,
                        1	,
                        1	,
                        1		};
            double[] y = {0.9895	,
                        0.9868	,
                        0.9642	,
                        0.9886	,
                        0.9853	,
                        0.9893	,
                        0.9665	,
                        0.9719	};
            double[,] x2 = {{0.4871	,
                            0.542	,
                            0.5288	,
                            0.4136	,
                            0.5239	,
                            0.4857	,
                            0.5307	,
                            0.3348	},
                            {0.5604	,
                            0.5821	,
                            0.4925	,
                            0.5866	,
                            0.5479	,
                            0.4203	,
                            0.4179	,
                            0.5013	}};
            double[,] x = {{0.4871	,
                            0.542	,
                            0.5288	,
                            0.4136	,
                            0.5239	,
                            0.4857	,
                            0.5307	,
                            0.3348	},
                            {0.5604	,
                            0.5821	,
                            0.4925	,
                            0.5866	,
                            0.5479	,
                            0.4203	,
                            0.4179	,
                            0.5013	},
                          {1	,
                        1	,
                        1	,
                        1	,
                        1	,
                        1	,
                        1	,
                        1		}};
            //double[,] x = {{0.4871	,
            //                0.542	,
            //                0.5288	,
            //                0.4136	,
            //                0.5239	,
            //                0.4857	,
            //                0.5307	,
            //                0.3348	},
            //                {0.5604	,
            //                0.5821	,
            //                0.4925	,
            //                0.5866	,
            //                0.5479	,
            //                0.4203	,
            //                0.4179	,
            //                0.5013	}};
            LinearRegression myLG = new LinearRegression();
            bool results = myLG.Regress(y, x, w);
            string result = ""+results+"\n"+myLG.C[0]+"\t"+myLG.C[1]+"\t"+myLG.C[2]+"\t";

            bool results2 = myLG.Regress(y, x2);
            string result2 = "" + results + "\n" + myLG.C[0] + "\t" + myLG.C[1] + "\t" + myLG.C[2] + "\t";
            this.richTextBox1.Text += result + "\n\n" + result2;
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //SimuAnalysis2();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            //int[] MeanResults = new int[4];
            //for (int m = 2; m <= 5; m++)
            //{
            //    for (int i = 0; i < rawDataList.Count; i += 5)
            //    {
            //        //System.Diagnostics.Debug.WriteLine("Processing " + (i / 5 + 1) + "/" + myLogs.Count / 5 + "...");
            //        double meanTime = 0;
            //        double meanEdit = 0;
            //        double medianTime = 0;
            //        double medianEdit = 0;

            //        List<double> times = new List<double>();
            //        List<double> edits = new List<double>();
            //        for (int j = 0; j < m; j++)
            //        {
            //            times.Add(rawDataList[i + j].TimeSpentTask);
            //            meanTime += rawDataList[i + j].TimeSpentTask;

            //            edits.Add(rawDataList[i + j].Proof_change_count);
            //            meanEdit += rawDataList[i + j].Proof_change_count;
            //        }

            //        times.Sort();
            //        edits.Sort();
            //        meanTime /= (times.Count);
            //        meanEdit /= (edits.Count);

            //        for (int j = 0; j < m; j++)
            //        {
            //            if (rawDataList[i + j].Quality >= 0)//positive
            //            {
            //                if (rawDataList[i + j].TimeSpentTask >= meanTime && rawDataList[i + j].Proof_change_count >= meanEdit)
            //                {
            //                    MeanResults[0]++;
            //                }
            //                else
            //                    MeanResults[1]++;
            //            }
            //            else//negative
            //            {
            //                if (rawDataList[i + j].TimeSpentTask >= meanTime && rawDataList[i + j].Proof_change_count >= meanEdit)
            //                {
            //                    MeanResults[2]++;
            //                }
            //                else
            //                    MeanResults[3]++;
            //            }
            //        }
            //    }

            //    string output = ""+m+"\t";
            //    output += (double)MeanResults[0] / (MeanResults[0] + MeanResults[1]) + "\t";
            //    output += (double)MeanResults[3] / (MeanResults[2] + MeanResults[3]) + "\n";
            //    richTextBox1.Text += output;
            //}
        }

        private void button8_Click(object sender, EventArgs e)
        {
            // SimuAnalysis3();
            SimuAnalysis2();
            //SimuAnalysis();
            
        }

        private void SimuAnalysis3()
        {
            AnalysisLogic3 analysisLogic = new AnalysisLogic3(rawDataList);

            int total = trainingSizeUpper / trainingSizeInterval * eachSimuluationUpperLimit * (workerSizeUpper - 1) * eachWorkerPickingSimuLimit;
            int current = 0;
            List<int> userIDs = analysisLogic.getAllUserIDs();
            List<int> internalIDs = new List<int>();
            for (int i = 0; i < 5; i++)
                internalIDs.Add(i);
            //for each number of workers
            string output = "";
            double[, ,] PosRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] NegRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] precisionRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] recallRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] fvalueRatio = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] fvalueRatio2 = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] accuracys = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];
            double[, ,] optimalY = new double[workerSizeUpper - 1, trainingSizeUpper / trainingSizeInterval, eachWorkerPickingSimuLimit];

            for (int WN = 2; WN <= workerSizeUpper; WN++)
            {
                //fixed # of workers, for each picking
                for (int k = 0; k < eachWorkerPickingSimuLimit; k++)
                {
                    //for each training size
                    for (int N = 1; N <= trainingSizeUpper / trainingSizeInterval; N++)
                    {
                        //for each simu for each training*worker picking
                        int run = eachSimuluationUpperLimit;
                        while (run > 0)
                        {
                            if (WN == 3)
                            {
                                int x = 1;
                            }

                            current++;
                            System.Diagnostics.Debug.WriteLine("Status: " + current + " out of " + total + " \n\n");
                            List<int> chosenIDs = new List<int>();
                            Random myR = new Random();
                            for (int i = 0; i < N * trainingSizeInterval; i++)
                            {
                                int nextId = myR.Next(0, userIDs.Count);
                                if (!chosenIDs.Contains(userIDs[nextId]))
                                    chosenIDs.Add(userIDs[nextId]);
                                else
                                    i--;
                            }

                            List<int> chosenInternalIDs = new List<int>();
                            for (int i = 0; i < WN; i++)
                            {
                                int nextId = myR.Next(0, internalIDs.Count);
                                if (!chosenInternalIDs.Contains(internalIDs[nextId]))
                                    chosenInternalIDs.Add(internalIDs[nextId]);
                                else
                                    i--;
                            }
                            analysisLogic.Evaluate(chosenIDs, chosenInternalIDs);
                            PosRatio[WN - 2, N - 1, k] += analysisLogic.CurrentPosRatio;
                            NegRatio[WN - 2, N - 1, k] += analysisLogic.CurrentNegRatio;
                            precisionRatio[WN - 2, N - 1, k] += analysisLogic.precision;
                            recallRatio[WN - 2, N - 1, k] += analysisLogic.recall;
                            //fvalueRatio[WN - 2, N - 1, k] += analysisLogic.fvalue;
                            //fvalueRatio2[WN - 2, N - 1, k] += analysisLogic.fvalue2;
                            //accuracys[WN - 2, N - 1, k] += analysisLogic.accuracy;
                            fvalueRatio[WN - 2, N - 1, k] = fvalueRatio[WN - 2, N - 1, k] > analysisLogic.fvalue ? fvalueRatio[WN - 2, N - 1, k] : analysisLogic.fvalue;
                            fvalueRatio2[WN - 2, N - 1, k] = fvalueRatio2[WN - 2, N - 1, k] > analysisLogic.fvalue2 ? fvalueRatio2[WN - 2, N - 1, k] : analysisLogic.fvalue2;
                            accuracys[WN - 2, N - 1, k] = accuracys[WN - 2, N - 1, k] > analysisLogic.accuracy ? accuracys[WN - 2, N - 1, k] : analysisLogic.accuracy;
                            optimalY[WN - 2, N - 1, k] += analysisLogic.optimalY;
                            //output += WN + "\t" + (k + 1) + "\t" + chosenIDs.Count + "\t" + analysisLogic.NewAnalyzeSelectProfiles(chosenIDs, chosenInternalIDs) + "\n";
                            //for (int mm = 0; mm < 2; mm++)
                            //{
                            //    analysisLogic.GetParameters(chosenIDs, chosenInternalIDs, mm);
                            //    for(int nn=3; nn>=0;nn--)
                            //        richTextBox1.Text += (mm+1)+"\t"+(nn)+"\t" + WN + "\t" + (k + 1) + "\t" + chosenIDs.Count + "\t" + analysisLogic.NewAnalyzeSelectProfiles(chosenIDs, chosenInternalIDs, nn) + "\n";
                            //}
                            run--;
                        }
                    }
                }
            }

            for (int i = 0; i < workerSizeUpper - 1; i++)
                for (int j = 0; j < trainingSizeUpper / trainingSizeInterval; j++)
                    for (int k = 0; k < eachWorkerPickingSimuLimit; k++)
                    {
                        output += "1\t" + (i + 2)
                                    + "\t" + (j + 1) * trainingSizeInterval + "\t"
                                    + (precisionRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    + (recallRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                            //+ (fvalueRatio[i, j, k] / eachSimuluationUpperLimit) + "\t"
                            //+ (fvalueRatio2[i, j, k] / eachSimuluationUpperLimit) + "\t"
                            //+ (accuracys[i, j, k] / eachSimuluationUpperLimit) + "\t"
                                    + (fvalueRatio[i, j, k]) + "\t"
                                    + (fvalueRatio2[i, j, k]) + "\t"
                                    + (accuracys[i, j, k]) + "\t"
                            //+ (optimalX[i, j, k] / eachSimuluationUpperLimit) 
                                    + "\n";
                    }

            richTextBox1.Text += output;
        }
    }
}
